package com.yanger.dao;

import com.yanger.pojo.Department;
import com.yanger.pojo.Employee;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;


@Repository
public class EmployeeDao {


    private static HashMap<Integer, Employee> employees = null;

    private static Integer initid = 1006;


    static {
        employees = new HashMap<>();
        employees.put(1001,new Employee(1001,"zs","xxxxxx@qq.com",1,new Department(101,"A")));
        employees.put(1002,new Employee(1002,"zs1","xxxxxx@qq.com4",0,new Department(102,"B")));
        employees.put(1003,new Employee(1003,"zs2","xxxxxx@qq.com3",1,new Department(103,"C")));
        employees.put(1004,new Employee(1004,"zs3","xxxxxx@qq.com2",0,new Department(104,"D")));
        employees.put(1005,new Employee(1005,"zs4","xxxxxx@qq.com1",1,new Department(105,"E")));

    }

    public Collection<Employee> getAllEmployee(){
        return employees.values();
    }

    public void addEmployee(Employee employee){
        if(employee.getId() != null){
            employee.setId(initid++);
        }

        employee.setDepartment(DepartmentDao.getDepartById(employee.getDepartment().getId()));

        employees.put(employee.getId(),employee);
    }

    public Employee getEmployeeById(int id){
        return employees.get(id);
    }

    public void deleteEmployee(Integer id){
        employees.remove(id);
    }

}
